<%@ page language="java" contentType="text/html; charset=UTF-8"   pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta charset="UTF-8">
	<title>用户中心</title>
	<script type="text/javascript" src="/static/js/jquery-1.10.2.min.js"></script>
	<script type="text/javascript" src="/static/js/jquery.cookie.js"></script>
</head>
<body>

<script type="text/javascript">
 	var baseUrl = "http://127.0.0.1:8080/phoenix-apps-shoppingcart";
 
 	var hostName = window.location.hostname;
 	function show(o){
 		var account= $.cookie('cart');
 		alert(account==undefined);
 	}
 	
	function insert(){
		//$.cookie("cart", "value");
		//跨域？
		$.cookie("cart", "value", {expires: 7, path: "/", domain: hostName});
		//alert(window.location.host);
		//alert(window.location.hostname);
 	}
 	
	function remov(){
		//$.cookie("cart", "value");
		//$.cookie("cart",null);
		//跨域？
		$.removeCookie("cart",{path: "/", domain:hostName });
		// $.cookie("cart",null, {expires: 7, path: "/", domain: "127.0.0.1", secure: true});
 	}
	
	//持久化后的查询
	function showPersist(){
 		$.ajax({
 			url:baseUrl+"/shoppingcart/shoppingcartlist",
 			type:'GET',
 			success:function(res){
 				$("#show").text(res.msg);
 				$.each(res.rs,function(i,v){
 					$("#show").append("/skuid="+v.skuId+"/skuCount="+v.skuCount)
 				})
 				
 			}
 		})
 	}
	function insertPersist(skuId,skuCount){
		$.ajax({
 			url:baseUrl+"/shoppingcart/cartAdd/"+skuId+"/"+skuCount,
 			type:'GET',
 			success:function(res){
 				$("#show").text(res.msg);
 			}
 		})
 	}
	function updatePersist(skuId,skuCount){
		$.ajax({
 			url:baseUrl+"/shoppingcart/updateCartItem/"+skuId+"/"+skuCount,
 			type:'GET',
 			success:function(res){
 				$("#show").text(res.msg);
 			}
 		})
 	}
	function removPersist(skuId){
		$.ajax({
 			url:baseUrl+"/shoppingcart/goodsDel/"+skuId,
 			type:'GET',
 			success:function(res){
 				$("#show").text(res.msg);
 			}
 		})
 	}
	
 </script>
 <span>cookie本地保存测试</span><br>
<button onclick="insert()">insert测试</button><br>
<button onclick="show()">show测试</button><br>
<button onclick="remov()">remove测试</button><br>
<span>登录后购物车</span><br>
<button onclick="showPersist()">show测试</button><br>
<button onclick="insertPersist(1,1)">insert测试</button><br>
<button onclick="updatePersist(1,1)">update测试</button><br>
<button onclick="removPersist(1)">remove测试</button><br>
查询结果:<div id="show"></div>
</body>
</html>